package com.example.anliku.controller;

import com.alibaba.fastjson.JSON;
import com.example.anliku.entity.Example;
import com.example.anliku.entity.ExampleKnowledge;
import com.example.anliku.entity.ExampleSee;
import com.example.anliku.entity.ExampleSeeBody.ExampleSeeRetBody;
import com.example.anliku.entity.Message;
import com.example.anliku.entity.teamBody.TeamMemberReturnBody;
import com.example.anliku.service.ExampleSeeService;
import com.example.anliku.service.ExampleService;
import com.example.anliku.service.TeamMemberNewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Api(tags = "案例模块")
@RestController
@RequestMapping("/api/example")
public class ExampleController {
    @Resource
    private ExampleService exampleService;

    @Resource
    private ExampleSeeService exampleSeeService;

    @Resource
    private TeamMemberNewService teamMemberNewService;


    @ApiOperation(value = "添加案例")
    @PostMapping("/one")
    public Message insert(Example example) {
        return exampleService.insertSelective(example);
    }

    @ApiOperation(value = "删除案例")
    @DeleteMapping("/delete")
    public Message delete(Integer exampleId) {
        return exampleService.deleteByPrimaryKey(exampleId);
    }

    @ApiOperation(value = "修改案例")
    @PostMapping("/put")
    public Message update(Example example) {
        return exampleService.updateByPrimaryKeySelective(example);
    }

    @ApiOperation(value = "获取所有案例")
    @GetMapping("/all")
    public Message selectAll() {
        return exampleService.selectAll();
    }

    @ApiOperation(value = "根据案例id获取案例")
    @GetMapping("/one")
    public Message selectByPrimaryKey(Integer exampleId) {
        return exampleService.selectByPrimaryKey(exampleId);
    }

    @ApiOperation(value = "获取所有案例所有知识点名称,评论,课程，可查看人")
    @GetMapping("/example/knowledge")
    public Message selectKnowledgeAll() {
        return exampleService.selectKnowledgeAll();
    }

    @ApiOperation(value = "修改案例当前审核状态")
    @PostMapping("/update")
    public Message updateExampleStateAndExampleCheckIdAndExampleAdviceByExampleId(int exampleState, String exampleCheckId, String exampleAdvice, int exampleId) {
        return exampleService.updateExampleStateAndExampleCheckIdAndExampleAdviceByExampleId(exampleState, exampleCheckId, exampleAdvice, exampleId);
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/search/test")
    public Message searchTest(@RequestParam Integer pageNum, @RequestParam Integer size) {
        return exampleService.searchTest(pageNum, size);
    }

    @ApiOperation(value = "根据发起人id返回所有的案例")
    @GetMapping("/selectAll/Example")
    public Message selectexampleUserIdByexample(String exampleUserId) {
        return exampleService.selectexampleUserIdByexample(exampleUserId);
    }

    @ApiOperation(value = "根据userId查询发布的案例信息")
    @GetMapping("/selectAll/userId")
    public Message selectAllByExampleUserIdAndExamplePublicState(String exampleUserId) {
        return exampleService.selectAllByExampleUserIdAndExamplePublicState(exampleUserId, 1);
    }

    @ApiOperation(value = "首页获取案例列表")
    @GetMapping("/selectExample")
    public Message selectExample() {
        return exampleService.returnAll();
    }

    @ApiOperation(value="根据userId查询案例知识点课程名")
    @GetMapping("/selectAll/userIdclazz")
    public Message selectByExampleUserId(String UserId){
        return exampleService.selectByExampleUserId(UserId);
    }

    @ApiOperation(value="返回最新5个案例")
    @GetMapping("/top")
    public Message top(){
        return exampleService.ruturnTop5();
    }

    @ApiOperation(value = "批量添加可查看成员")
    @PostMapping("/see")
    public Message see(String list) {
        List<ExampleSee> exampleSeeList = JSON.parseArray(list,ExampleSee.class);
        return exampleSeeService.insertList(exampleSeeList);
    }

    @ApiOperation(value="批量添加可查看成员(body)")
    @PostMapping("/insertMemberBody")
    public Message insertListBody (@RequestBody List<ExampleSeeRetBody> exampleSeeRetBodies){
        return exampleSeeService.batchInsert(exampleSeeRetBodies);
    }

    @ApiOperation(value = "根据主键删除案例与可查看人对应关系")
    @DeleteMapping("/deletesee")
    public Message deletesee(Integer exampleSeeId) {
        return exampleSeeService.deleteByPrimaryKey(exampleSeeId);
    }

    @ApiOperation(value="获取本人所在团队的所有团队")
    @GetMapping("/team")
    public Message team(String userId){
        return teamMemberNewService.selectTeamMemberNewIdByTeamMemberNewUserId(userId);
    }

    @ApiOperation(value="根据userid获取自己可以查看的案例")
    @GetMapping("/mysee")
    public Message mysee(String exampleSeeUserId){
        return exampleSeeService.selectByExampleSeeUserId(exampleSeeUserId);
    }
}
